#include <bits/stdc++.h>
#define int long long
using namespace std;

int findk(int x) {
    int k = __lg(x);
    if (1 << k == x) return k;
    else return k + 1;
}

const int N = 200005, K = 20;

int n, m, lvl, a[N], c[N], d[K][N], cnt[K], val[K][N], sum[K][N], ans[N];

void solve() {
    // cerr << "Solving" << endl;
    for (int i = 0; i <= lvl; i++)
        for (int j = 1; j <= cnt[i]; j++)
            val[i][j] = -1;
    // for (int i = 1; i <= cnt[0]; i++)
    //     val[0][i] = -1;
    for (int i = 1; i <= cnt[0]; i++)
        sum[0][i] = i;
    for (int i = 1; i <= lvl; i++)
        for (int j = 1; j <= cnt[i]; j++)
            sum[i][j] = sum[i - 1][j * 2 - 1] + sum[i - 1][j * 2];
    for (int i = 1; i <= n; i++) {
        // cerr << "Adding " << i << endl;
        // 對於每一個人,依次把他們加入
        val[0][i] = a[i];
        int p = (i + 1) / 2;
        for (int j = 1; j <= lvl; j++) {
            // cerr << "currently at " << j << " " << p << endl;
            int ls = p * 2 - 1, rs = p * 2;
            if (d[j][p]) swap(ls, rs);
            int x = val[j - 1][ls], y = val[j - 1][rs];
            // 擂主為 x,另一個為 y
            if (x == -1) {
                sum[j][p] = sum[j - 1][ls] + sum[j - 1][rs];
                val[j][p] = -1;
            } else {
                if (x < j) sum[j][p] = sum[j - 1][rs], val[j][p] = y;
                else sum[j][p] = sum[j - 1][ls], val[j][p] = x;
            }
            p = (p + 1) / 2;
        }
        ans[i] = sum[findk(i)][1];
        // ans[i] = sum[lvl][1];
    }
    // for (int i = 1; i <= n; i++)
    //     cerr << ans[i] << " ";
    // cerr << endl;
    int final = 0;
    for (int i = 1; i <= m; i++)
        final ^= (i * ans[c[i]]);
    cout << final << endl;
}

signed main() {
    freopen("arena.in", "r", stdin);
    freopen("arena.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= m; i++)
        cin >> c[i];
    lvl = findk(n);
    for (int i = 0, tot = 1 << lvl; i <= lvl; i++, tot /= 2)
        cnt[i] = tot;
    for (int i = 1; i <= lvl; i++)
        for (int j = 1; j <= cnt[i]; j++) {
            char ch;
            cin >> ch;
            d[i][j] = ch - '0';
        }
    int T;
    cin >> T;
    while (T--) {
        int X[4];
        for (int i = 0; i < 4; i++)
            cin >> X[i];
        for (int i = 1; i <= n; i++)
            a[i] ^= X[i % 4];
        // cerr << "a: ";
        // for (int i = 1; i <= n; i++)
        //     cerr << a[i] << " ";
        // cerr << endl;
        solve();
        for (int i = 1; i <= n; i++)
            a[i] ^= X[i % 4];
    }
    return 0;
}